package cn.com.infcn.spider.io.input;

import java.util.ArrayList;
import java.util.List;

import org.nutz.lang.Mirror;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import cn.com.infcn.spider.io.ConfigParse;

public class InputFactory {
	public static Input[] create(String input, String jobName) {

		List<Input> result = new ArrayList<>();

		JSONArray parse = ConfigParse.parse(input);

		for (Object obj : parse) {
			JSONObject job = (JSONObject) obj;
			String type = job.getString("type");

			try {
				result.add((Input) Mirror.me(Class.forName("cn.com.infcn.spider.io.input.impl." + type + "Input")).born(job.getJSONObject("obj"), jobName));
			} catch (ClassNotFoundException e) {
				e.printStackTrace();
			}

		}

		return result.toArray(new Input[result.size()]);
	}
}
